package com.example.network

import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import com.example.kotlinandroidstudy.api.RetrofitClient
import com.example.network.api.RequestApi
import com.example.network.databinding.ActivityMainBinding
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.functions.Consumer
import io.reactivex.schedulers.Schedulers


class MainActivity : AppCompatActivity() {

    var binding : ActivityMainBinding ?= null;

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityMainBinding.inflate(layoutInflater)
        binding?.let {
            setContentView(it.root)
            it.button.setOnClickListener{getRetrofit()}
        }
    }

    //普通的网络请求
    fun getRetrofit(){
        RetrofitClient<RequestApi>().getService(RequestApi::class.java)?.let {
            it.gethttp()
                .subscribeOn(Schedulers.io())
                .unsubscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(Consumer<String> {
                    Log.d("zdl","=====$it")
                },Consumer<Throwable>{
                    Log.d("zdl","=====${it.message}")
                })
        }
    }


}


